﻿using System;
using System.Collections.Generic;
using System.Text;
using CookComputing.XmlRpc;
using System.Collections.ObjectModel;
using System.Net;

namespace TorrentRelatedEntities
{
	public class ServProtUser_1
	{
		public int ID {get; set;}
		//[XmlRpcMissingMapping (MappingAction.Ignore)]
		//public string Guid { get; set; }
		//[XmlRpcMissingMapping (MappingAction.Ignore)]
		public string SiteUserID { get; set; }
		public string PID { get; set; }
		public string UserName { get; set; }
		public int IDLevel { get; set; }
	}

	class TrackerIdentity
	{
		public static readonly string AccessClient = "client";
		public static readonly string AccessSite = "site";
		public static readonly string AccessControl = "control";
		public string Access = AccessClient;
		public string Login = string.Empty;
		public string Password = string.Empty;
		public string PID = string.Empty;
	}

	public class SiteAcccess
	{
		public string access = "site";
		public string site_key = "{6E929063-E146-4ECE-AD18-5D0B41561501}";
	}

	//public class

	public interface ITrackerAPI : IXmlRpcProxy
	{
		//[XmlRpcMethod]
		//ServProtUser_1[] GetAllTrackerUsers ();
		//[XmlRpcMethod]
		//void AddTrackerUser (string Name, string SiteUserID);
		//[XmlRpcMethod]
		//ServProtUser_1 GetUserBySiteUserID (string SiteUserID);
		//[XmlRpcMethod]
		//bool DeleteTrackerUserBySiteUserID (string SiteUserID);
		[XmlRpcMethod]
		void SiteAddTrackerUser (SiteAcccess Access, string SiteUserID, string UserDisplayableName, string Login, string Password);
		[XmlRpcMethod]
		void SiteDeleteTrackerUser (SiteAcccess Access, string SiteUserID);
		[XmlRpcMethod]
		void SiteAddTrackerDownload (SiteAcccess Access, string SiteDownloadID, string DownloadDisplayableName, string DownloadShortDescription);
		[XmlRpcMethod]
		void SiteDeleteTrackerDownload (SiteAcccess Access, string SiteDownloadID);
		[XmlRpcMethod]
		void SiteAddTrackerUserDownloadAssociation (SiteAcccess Access, string SiteUserID, string SiteDownloadID);
		[XmlRpcMethod]
		void SiteDeleteTrackerUserDownloadAssociation (SiteAcccess Access, string SiteUserID, string SiteDownloadID);
		[XmlRpcMethod]
		void SiteGetTrackerUserStatistics (SiteAcccess Access, string SiteUserID);
	}
	//[DebuggerStepThrough]
	public static class ServerDataInterconnect
	{
        //public static string ServerAddrString = "http://192.168.75.110:35987/tracker-api.php";
		//public static string ServerAddrString = "http://92.255.114.35:41001/tracker-site-api.php";
		public static string ServerAddrString = "http://92.255.114.35:41001/tracker/code/tracker-site-api.php";
		public static ITrackerAPI TrackerAPIProxy = null;
		public static ITrackerAPI GetTrackerAPIProxy ()
		{
			//if (XMLRpcLog == null) XMLRpcLog = new ObservableCollection<string> ();
			TrackerAPIProxy = XmlRpcProxyGen.Create<ITrackerAPI> ();
			TrackerAPIProxy.Url = ServerAddrString;
			TrackerAPIProxy.Timeout = 10000;
			//TrackerAPIProxy.ResponseEvent += new XmlRpcResponseEventHandler (TrackerAPIProxy_ResponseEvent);
			return TrackerAPIProxy;
		}
		static void TrackerAPIProxy_ResponseEvent (object sender, XmlRpcResponseEventArgs args)
		{
			throw new NotImplementedException ();
		}
		//public static ObservableCollection<string> XMLRpcLog { get; set; }
		public static void EnsureInitialized ()
		{
			if (TrackerAPIProxy == null) GetTrackerAPIProxy ();
		}
		//public static ServProtUser_1[] GetUsers ()
		//{
		//    EnsureInitialized ();
		//    ServProtUser_1[] users = null;
		//    try
		//    {
		//    users = TrackerAPIProxy.GetAllTrackerUsers ();
		//    }
		//    catch (IndexOutOfRangeException e)
		//    {
		//        //e.
		//    }
		//    catch (WebException e)
		//    {
		//        int i = 5;
		//    }
		//    //catch
		//    return users;
		//}
		//public static void AddUser (string Name, string site_user_id)
		//{
		//    EnsureInitialized ();
		//    TrackerAPIProxy.AddTrackerUser (Name, site_user_id);
		//}
		//public static ServProtUser_1 GetUserBySiteUserID (string SiteUserID)
		//{
		//    EnsureInitialized ();
		//    return TrackerAPIProxy.GetUserBySiteUserID (SiteUserID);
		//}
		//public static bool DeleteUserBySiteUserID (string SiteUserID)
		//{
		//    EnsureInitialized ();
		//    return TrackerAPIProxy.DeleteTrackerUserBySiteUserID (SiteUserID);
		//}
		//public static AddTorrent (string )
		//{

		//}
		static ServerDataInterconnect ()
		{
			EnsureInitialized ();
		}
	}
}
